package com.xiaoshuidi.cloud.module.member.controller.admin.topics;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.member.controller.admin.topics.vo.TopicListVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.topics.vo.TopicUpdateStatusVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.topics.vo.TopicsCreateVO;
import com.xiaoshuidi.cloud.module.member.controller.admin.topics.vo.TopicsDetailVo;
import com.xiaoshuidi.cloud.module.member.controller.admin.topics.vo.TopicsPageVO;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.topics.MemberTopicsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 社区活动话题")
@RestController
@RequestMapping(ApiConstants.NAME + "/topics")
@Validated
public class MemberTopicsController {
    @Resource
    private MemberTopicsService memberTopicsService;

    @PostMapping("/create")
    @Operation(summary = "创建话题")
    public CommonResult<Boolean> create(@Valid @RequestBody TopicsCreateVO createReqVO) {
        return success(memberTopicsService.create(createReqVO));
    }

    @PostMapping("/update-status")
    @Operation(summary = "启用禁用话题")
    public CommonResult<Boolean> updateStatus(@Valid @RequestBody TopicUpdateStatusVO topicUpdateStatusVO) {
        return success(memberTopicsService.updateStatus(topicUpdateStatusVO));
    }

    @PostMapping("/edit")
    @Operation(summary = "编辑话题")
    public CommonResult<Boolean> edit(@Valid @RequestBody TopicsCreateVO createReqVO) {
        return success(memberTopicsService.edit(createReqVO));
    }

    @GetMapping("/get-by-id/{id}")
    @Operation(summary = "查看话题详情")
    public CommonResult<TopicsDetailVo> getById(@PathVariable("id") Long id) {
        return success(memberTopicsService.getById(id));
    }


    @PostMapping("/get-page")
    @Operation(summary = "获得话题列表")
    public CommonResult<PageResult<TopicListVO>> getPage(@Valid @RequestBody TopicsPageVO pageVO) {
        PageResult<TopicListVO> pageResult = memberTopicsService.getPage(pageVO);
        return success(pageResult);
    }
}
